package com.lis.scf.controller;

import com.lis.scf.common.dto.CurrentUserDTO;
import com.lis.scf.common.dto.ResponseDTO;
import com.lis.scf.service.UserService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.security.core.Authentication;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("api/users")
@RequiredArgsConstructor
@Tag(name = "用户管理接口", description = "处理用户信息查询、修改等操作")
public class UserController {

    private final UserService userService;

    /**
     * 获取当前用户信息
     * 获取登录用户的基本信息和所属企业
     */
    @GetMapping("/current")
    @PreAuthorize("isAuthenticated()") // 仅允许已登录用户访问
    @Operation(
            summary = "获取当前登录用户信息",
            description = "返回当前登录用户的基本信息（ID、姓名、手机号等）及所属企业信息"
    )
    @ApiResponse(
            responseCode = "200",
            description = "查询成功",
            content = @Content(schema = @Schema(implementation = CurrentUserDTO.class))
    )
    public ResponseDTO<CurrentUserDTO> getCurrentUser(Authentication authentication) {

        // 从认证信息中获取当前登录用户名
        String username = authentication.getName();

        CurrentUserDTO currentUser = userService.getCurrentUserInfo(username);
        return ResponseDTO.success(currentUser);
    }


    /**
     * 修改用户密码
     */
    @GetMapping("/password")
    public void password(){

    }

}
